<script setup lang="ts">
import { getAllDep } from '@/api/consult'
import type { TopDep } from '@/types/consult'
import { onMounted, ref, computed } from 'vue'
import { consultStore } from '@/stores'
const store = consultStore()
const active = ref(0)
const oneConsult = ref<TopDep[]>([])
onMounted(() => {
  getAllDep<TopDep[]>().then((res) => {
    oneConsult.value = res.data
  })
})
// 利用计算属性或者侦听器达到点击一级科室显示二级科室的需求
const subDep = computed(() => oneConsult.value[active.value]?.child)
</script>

<template>
  <div class="consult-dep-page">
    <cp-nav-bar title="选择科室" />
    <div class="wrapper">
      <van-sidebar v-model="active">
        <van-sidebar-item v-for="item in oneConsult" :key="item.id" :title="item.name" />
      </van-sidebar>
      <div class="sub-dep">
        <router-link @click="store.setDep(ite.id)" to="/consult/illness" v-for="ite in subDep" :key="ite.id">
          {{ ite.name }}
        </router-link>
      </div>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.van-sidebar {
  width: 114px;
  &-item {
    padding: 14px;
    color: var(--cp-tag);
    &--select {
      color: var(--cp-main);
      font-weight: normal;
      &::before {
        display: none;
      }
    }
  }
}
.wrapper {
  height: calc(100vh - 46px);
  overflow: hidden;
  display: flex;
  .sub-dep {
    flex: 1;
    height: 100%;
    overflow-y: auto;
    > a {
      display: block;
      padding: 14px 30px;
      color: var(--cp-dark);
    }
  }
}
.consult-dep-page {
  padding-top: 46px;
}
</style>
